package com.vcredit.creditcat.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/** 从spring容器获取bean
 * @description 
 * @author zhangxingong
 * @version $Id: SpringContextHolder.java, v 0.1 Jul 3, 2017 10:44:22 AM zhangxingong Exp $
 */
@SuppressWarnings("static-access")
public class SpringContextHolder implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
          this.applicationContext = applicationContext;
	}
	
	public static Object getBean(String name) throws BeansException{
		return applicationContext.getBean(name);
	}

	public static <T> T getBean(String name, Class<T> requiredType) throws BeansException{
       return applicationContext.getBean(name,requiredType);
	}

	public static<T> T getBean(Class<T> requiredType) throws BeansException{
		return applicationContext.getBean(requiredType);
	}

}
